﻿namespace IBTrader.Indicator.CandleStick
{
    using IBTrader.Charts;

    /// <summary>
    /// Volume-Weighted Average Price (VWAP) is exactly what it sounds like: the average price weighted by volume. 
    /// VWAP equals the dollar value of all trading periods divided by the total trading volume for the current day. 
    /// Calculation starts when trading opens and ends when trading closes. 
    /// Because it is good for the current trading day only, intraday periods and data are used in the calculation.
    /// </summary>
    class VWAP : BaseVolume
    {
        private readonly Prices typical;
        public VWAP(Worker worker, int interval = 12, int interval2 = 12, int interval3 = 12) : base(worker, 0, interval, interval2) { typical = new Prices(interval3); }
        protected override void Add(object _, Item item)
        {
            var volume = item.Volume;
            Prices.Add(volume);
            typical.Add(item.Typical * volume);
            OnHit(item.CloseLine, typical.Sum / Prices.Sum);
        }
    }
}